FastDFS
====================================================

一：安装
1.1：介绍
        tracker server：跟踪服务器，调度；在内存中记录所有存储组和存储服务器的状态信息；
        storage server：存储服务器，文件（data）和文件属性（metadata）；
        client：客户端，业务请求发起方，通过专用接口基于TCP协议与tracker以及storage server进行交互；


1.2：准备文件
    ~]# yum -y install unzip gcc pcre-devel  openssl-devel
    fastdfs 官方地址：https://github.com/happyfish100
    nginx 官方地址：http://nginx.org/en/download.html
    源码包：
        fastdfs-master.zip  
        fastdfs-nginx-module-master.zip  
        libfastcommon-master.zip  
        nginx-1.10.0.tar.gz


1.3：环境介绍
    tracker 和 client：172.18.21.70 
    storage 和 nginx：172.18.21.71
    storage 和 nginx：172.18.21.72


1.4：安装 tracker （172.18.21.70）
    ~]# cd libfastcommon
    ~]# ./make.sh
    ~]# ./make.sh install

    ~]# fastdfs-master
    ~]# ./make.sh
    ~]# ./make.sh install

    ~]# mkdir /data/fdfs/tracker -pv
    ~]# cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
    ~]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf


1.5：安装 storage 和 nginx（172.18.21.71  172.18.21.72）
    ~]# cd libfastcommon
    ~]# ./make.sh
    ~]# ./make.sh install

    ~]# fastdfs-master
    ~]# ./make.sh
    ~]# ./make.sh install

    ~]# mkdir /data/fdfs/storage/0 -pv
    ~]# cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
    ~]# cp fastdfs-master/conf/http.conf  /etc/fdfs/
    ~]# cp fastdfs-master/conf/mime.types /etc/fdfs/
    ~]# cp fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/

    nginx 编译安装：
        ~]# useradd -r nginx
        ~]# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --add-module=../fastdfs-nginx-module-master/src
        
        ./configure --prefix=/usr/local/fastdfsnginx --conf-path=/etc/fastdfsnginx/nginx.conf  --user=nginx --group=nginx --add-module=../fastdfs-nginx-module-master/src
        ~]# make && make install


二：配置

2.1：配置 tracker （172.18.21.70）
    ~]# vim /etc/fdfs/tracker.conf
        base_path=/data/fdfs/tracker

    启动：
    ~]# service fdfs_trackerd start
    ~]# ss -tnl
        *:22122
        # 备注：监听端口为 22122


2.2：配置 client （172.18.21.70）
    base_path=/data/fdfs/storage
    tracker_server=172.18.21.70:22122


2.3：配置 storage （172.18.21.71  172.18.21.72）
    ~]# vim /etc/fdfs/storage.conf
        base_path=/data/fdfs/storage
        store_path0=/data/fdfs/storage/0
        tracker_server=172.18.21.70:22122

    启动：
    ~]# service fdfs_storaged start
    ~]# ss -tnl
         *:23000 
        # 备注：监听端口为 23000

    启动后创建软连接：
    ~]# ln -sv /data/fdfs/storage/0/data/{,M00}
    ‘/data/fdfs/storage/0/data/M00’ -> ‘/data/fdfs/storage/0/data/’


2.4：配置 nginx（172.18.21.71  172.18.21.72）并启动
    ~]# vim /etc/nginx/nginx.conf
        server {
            .....
            location ~ /group[0-9]+/M00/ {
                root /data/fdfs/storage/0/data/;
                ngx_fastdfs_module;
            }
            .....
        }

    nginx启动：/usr/local/nginx/sbin/nginx
    nginx语法测试：/usr/local/nginx/sbin/nginx -t
    nginx停止：/usr/local/nginx/sbin/nginx -s stop


2.5：配置 mod_fastdfs.conf
    ~]# vim /etc/fdfs/mod_fastdfs.conf

        base_path=/data/fdfs/storage
        tracker_server=172.18.21.70:22122
        group_name=group1
        url_have_group_name = true
        store_path_count=1
        store_path0=/data/fdfs/storage/0

        group_count = 1
        [group1]
        group_name=group1
        storage_server_port=23000
        store_path_count=1
        store_path0=/data/fdfs/storage/0



三：测试

3.1：上传文件：fdfs_upload_file
    ~]# fdfs_upload_file /etc/fdfs/client.conf /usr/share/wallpapers/CentOS7/contents/images/2560x1600.jpg
        group1/M00/00/00/rBIVR1doVOSAD7ARAA6q2wjnW8s426.jpg

3.2：查看文件信息： fdfs_file_info
    ~]# fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/rBIVR1doVOSAD7ARAA6q2wjnW8s426.jpg
        source storage id: 0
        source ip address: 172.18.21.71
        file create timestamp: 2016-06-21 04:41:08
        file size: 961243
        file crc32: 149380043 (0x08E75BCB)

3.2：文件下载：fdfs_download_file
    ~]# fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/rBIVR1doVOSAD7ARAA6q2wjnW8s426.jpg ./a.jpg

3.4：浏览器访问
    http://172.18.21.71/group1/M00/00/00/rBIVR1doVOSAD7ARAA6q2wjnW8s426.jpg


四：查看状态

    storage：
        ~]# fdfs_monitor /etc/fdfs/storage.conf

    client：
        ~]# fdfs_monitor /etc/fdfs/client.conf


===================================================
date_default_timezone_set('PRC'); 
// echo 
// strlen(time());
// 1471428024.609


// echo 1471428024609 / 1000;

echo date('Y-m-d H:i:s', 1471428024);


// 2016-08-17 10:00:24

fdfs_upload_file /etc/fdfs/client.conf /usr/share/wallpapers/CentOS7/contents/images/2560x1600.jpg
group1/M00/00/00/Ciy4VVe2ZUKAUHHmAA6q2wjnW8s099.jpg

fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/Ciy4VVe2ZUKAUHHmAA6q2wjnW8s099.jpg

fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgSRle0i8SAZ2lNAA6q2wjnW8s034.jpg ~/a.jpg



    http://192.168.18.70:8088/group1/M00/00/00/rBIVR1doVOSAD7ARAA6q2wjnW8s426.jpg

service fdfs_trackerd stop
service fdfs_storaged stop

service fdfs_trackerd start
service fdfs_storaged start

vim /etc/fastdfsnginx/nginx.conf
/usr/local/fastdfsnginx/sbin/nginx -s stop
/usr/local/fastdfsnginx/sbin/nginx
/usr/local/fastdfsnginx/sbin/nginx -s reload
cat /var/log/fastdfsnginx/error.log

mkdir -pv /var/run/fastdfsnginx/
10.44.184.85
101.200.221.231

 ln -sv /data/fdfs/storage/0/data/{,M00}

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h



ls /usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/

extension=fastdfs_client.so

[root@localhost php5]# php -m | grep fastdfs_client
fastdfs_client
